<?php
session_start();
 $conn=mysql_connect("localhost","root","") or die (" không kết nối được máy chủ");
mysql_select_db("linhkienmt",$conn);
?>
<html>

<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
<link href="css/mau.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.dm {
     font-size:18px;
	 background-image:url(anh/nut/nut.jpg);
	 color:#FFCC33;
	 font-weight:bold;
	 }
.con {
       
       background:#00CCFF;
	   font-size:18px;
	   }
div#menut
    { margin-top:1px;
	  margin-left:1px;
	  line-height:1.5em;
	  width:162px;
	  	  }
* {margin:0;
   padding:0;
   }
    div#menut ul li:hover { 
							
	                          width:160px;}

  
 div#menut ul li
                { position:relative;
				border-bottom:1px solid #bccdd8;
				border-top:1px solid #bccdd8;
				border-left:1px solid #bccdd8;
				border-right:1px solid #bccdd8;
				background-image:url(anh/nut/menu_bg.jpg);
			
				}
div#menut ul li a {
					color:#FFFFFF;
                   text-decoration:none;
				   padding:5px;
				   }
	 

div#menut ul { list-style:none;
              border:1px solid #bcbd8;
			  }
div#menut ul li a:hover
                 { text-decoration:underline;
				 }
div#menut ul li ul { position:absolute;
                      top:1px;
					  left:160px;
					  display:none;
					  }
div#menut ul li:hover ul
                     { display:block;
					   width:160px;
					   }
.style3 {
	color: #FF0066;
	font-weight: bold;
}
.style4 {color: #66FF00}
.style5 {
	color: #000099;
	font-weight: bold;
}
			  
-->
</style>
</head>
<body>
             <td style="text-align: center; width: 597px" valign="top">
                
</td>
	</tr>	
        <tr>
		<td><table align="center" cellpadding="0" cellspacing="0" width="520"><tr>
		  <td><TABLE cellSpacing=0 cellPadding=0 width=520 
                        align=center background="hinh anh/bg11.gif">
            <TBODY background="hinh anh/bg11.gif">
              <TR>
               
                <TD><H2 class="dm">GIỎ HÀNG CỦA BẠN</H2></TD>
              </TR>
              <TR>
                <TD 
                            style="BORDER-RIGHT: #009900 1px solid; BORDER-TOP: #009900 1px solid; BORDER-LEFT: #009900 1px solid; BORDER-BOTTOM: #009900 1px solid" 
                            colSpan=4>
                                    <p>
<tr>
        <td width="630" height="46" valign="middle"><div align="center" class="style1">Giỏ hàng </div></td>
        <td width="1"></td>
      </tr>
      <tr>
        <td height="113" valign="top"><?php
					$conn=mysql_connect("localhost","root","") or die("lỗi kết nối!");
						mysql_select_db("linhkienmt",$conn);
						if(@$_SESSION["Cart"]=="")
						{
							@$Cart = array();
							$_SESSION["Cart"]=$Cart;
						}
						function add_item($intID) {
							$r = check_duplicate($intID);
							if(!$r) { 
								$intCount = count($_SESSION["Cart"]);   //Dem so mat hang trong gio
								$arrItem = array();                    //Tao mang chua chi tiet san pham
								$arrItem["id"]= $intID;
								$arrItem["qty"] = 1;
								$_SESSION["Cart"][$intCount] = $arrItem;
							}
						}
						function check_duplicate($intID) {
							$r = false;
							for($i=0; $i<count($_SESSION["Cart"]); $i++) {
								if($_SESSION["Cart"][$i]["id"] == $intID) {
									$_SESSION["Cart"][$i]["qty"] += 1;
									$r = true;
								}
							}
							return $r;
						}
						function update_item($intID, $qty) {
							for($i=0; $i<count($_SESSION["Cart"]); $i++) {
								if($_SESSION["Cart"][$i]["id"] == $intID) {
									$_SESSION["Cart"][$i]["qty"] = $qty;
									break;
								}
							}
						}
						
						function remove_item($intID) {
							for($i=0; $i<count($_SESSION["Cart"]); $i++) {
								if($_SESSION["Cart"][$i]["id"] == $intID) {
									array_splice($_SESSION["Cart"], $i, 1);
									break;
								}
							}
						}
						function remove_allitem() {
							for($i=0; $i<count($_SESSION["Cart"]); $i++) 
							{
						
									array_splice($_SESSION["Cart"], $i);
						
						
							}
						}
						function print_item() {
							for($i=0; $i<count($_SESSION["Cart"]); $i++) {
								print "ID: ".$_SESSION["Cart"][$i]["id"];
								print "<BR>";
								print "QTY: ".$_SESSION["Cart"][$i]["qty"];
								print "<BR>";
								print "-------------------------";
								print "<BR>";
							}
						}
		
		if($_GET["id"] != "")add_item($_GET["id"]);
		if(count($_SESSION["Cart"]) == 0) $none = true;
		else $none = false;
		?>
            <table width="610" height="330"  border="1" cellpadding="5" cellspacing="0" bgcolor="#CCCCFF">
              <tr>
                <td width="651" height="282"><?php
			  		if(!$none) {
			  ?>
                    <div align="center"><strong>Danh s&aacute;ch s&#7843;n ph&#7849;m qu&yacute; kh&aacute;ch &#273;&atilde; ch&#7885;n </strong> </div>
                  <table width="100%"  border="1" cellpadding="2" cellspacing="1">
                      <!--DWLayoutTable-->
                      <tr>
                        <td width="31" height="44" class="gh1">STT</td>
                        <td width="38" class="gh1">M&atilde; h&agrave;ng</td>
                        <td width="179" class="gh1">T&ecirc;n h&agrave;ng</td>
                        <td width="58" align="right" class="gh1">Gi&aacute; (VN&#272;)</td>
                        <td width="138" align="right" valign="top" class="gh1">S&#7889; l&#432;&#7907;ng</td>
                        <td width="78" align="right" valign="top" class="gh1">T&#7893;ng c&#7897;ng</td>
                        <td width="84" align="center" class="gh1">X&oacute;a</td>
                      </tr>
                      <?php
				  $stt=1;
				  $total=0;
				  for($i=0; $i<count($_SESSION["Cart"]); $i++) {				  	
					$sql = "SELECT * FROM sp WHERE masp='".$_SESSION["Cart"][$i]["id"]."'";
					//print $sql;
				  	$r = mysql_query($sql,$conn);
					$row = mysql_fetch_array($r);
									  $stt=1+$i;
				  ?>
                      <form action="giohang1.php" method="post" name="name<?php echo $i;?>" id="name<?php echo $i;?>">
                        <tr>
                          <td height="30" class="gh1"><?php echo $stt;?></td>
                          <td class="gh1"><?php echo $row["masp"];?></td>
                          <td class="gh1"><a href="chitiet.php?mas=<?php echo $_SESSION["Cart"][$i]["id"];?>" class="gh1"> <?php echo $row[2];?> </a></td>
                          <td align="right" class="gh1"><?php echo number_format($row["dongia"]);?></td>
                          <td align="right" valign="top" class="gh1"><p align="right">
                              <input type="hidden" name="id" value="<?php echo $_SESSION["Cart"][$i]["id"];?>" />
                              <input name="qty" value="<?php echo $_SESSION["Cart"][$i]["qty"];?>" size="1" class="txt_10px" />
                              <input name="submit" type="submit" class="txt_10px" value="update" />
                              </span></p></td>
                          <td align="right" valign="top" class="gh1"><?php  print number_format($row["dongia"]*$_SESSION["Cart"][$i]["qty"]); ?></td>
                          <td align="center" class="gh"><a href="giohangxoa.php?id=<?php echo $_SESSION["Cart"][$i]["id"];?>" >Xóa</a></td>
                        </tr>
                      </form>
                    <?php
					  $total+=$row["dongia"]*$_SESSION["Cart"][$i]["qty"];
				  }
				  ?>
                      <tr>
                        <td height="25">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td colspan="2" align="right" valign="top" >T&#7893;ng gi&aacute; tr&#7883; &#273;&#417;n h&agrave;ng</td>
                        <td align="right" valign="top" class="gh1"><?php echo number_format($total);?></td>
                        <td>&nbsp;</td>
                      </tr>
                    </table>
                  <?php
				}//close if
				else {
				?>
                    <table width="100%"  border="0" cellspacing="1" cellpadding="2">
                      <tr>
                        <td align="center" ><strong>Gi&#7887; h&agrave;ng c&#7911;a b&#7841;n &#273;ang r&#7895;ng</strong></td>
                      </tr>
                    </table>
                  <?php
				}
				?>
                    <table width="100%"  border="0" cellpadding="2" cellspacing="1">
                      <!--DWLayoutTable-->
                      <tr>
                        <td width="1" height="44">&nbsp;</td>
                        <td width="174" align="left" valign="middle"><a href="trangchu.php"><strong>Quay l&#7841;i mua h&agrave;ng</strong></a></td>
                        <td width="133" valign="middle"><div align="left"><a href="##.php" ><strong>X&oacute;a t&#7845;t c&#7843;</strong></a></div></td>
                        <td width="223" align="right" valign="middle"><div align="left"><a href="phuongthucthanhtoan.php"><strong>Ph&#432;&#417;ng th&#7913;c thanh to&aacute;n</strong></a></div></td>
                      </tr>
                  </table></td>
              </tr>
          </table></td>
      
      </tr>
                  </p>
                
            </TBODY>
		    </TABLE>
		</table></td>
								  </table></td>
    </tr>
    
    
</body>

<!-- Mirrored from www.suaonline.com.vn/?HOME/VN/ by HTTrack Website Copier/3.x [XR&CO'2010], Tue, 21 Dec 2010 13:15:47 GMT -->
</html>
